<template>
  <p-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">

        <p-form-item label="一级工序名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'processOneNamae', validatorRules.processOneNamae]" placeholder="请输入一级工序名称"></p-input>
        </p-form-item>
        <p-form-item label="一级工序编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'processOneCode', validatorRules.processOneCode]" placeholder="请输入一级工序编码"></p-input>
        </p-form-item>
        <p-form-item label="二级工序名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'processTwoName', validatorRules.processTwoName]" placeholder="请输入二级工序名称"></p-input>
        </p-form-item>
        <p-form-item label="二级工序编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'processTwoCode', validatorRules.processTwoCode]" placeholder="请输入二级工序编码"></p-input>
        </p-form-item>
        <p-form-item label="是否线长确认" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'isLineleaderConfirm', validatorRules.isLineleaderConfirm]" placeholder="请输入是否线长确认"></p-input>
        </p-form-item>
        <p-form-item label="是否首检" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'isFirstCheck', validatorRules.isFirstCheck]" placeholder="请输入是否首检"></p-input>
        </p-form-item>
        <p-form-item label="日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'isDate', validatorRules.isDate]" placeholder="请输入日期"></p-input>
        </p-form-item>
        <p-form-item label="品号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'isMcode', validatorRules.isMcode]" placeholder="请输入品号"></p-input>
        </p-form-item>
        <p-form-item label="线别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'isLinetype', validatorRules.isLinetype]" placeholder="请输入线别"></p-input>
        </p-form-item>
        <p-form-item label="工单" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'isMobillno', validatorRules.isMobillno]" placeholder="请输入工单"></p-input>
        </p-form-item>
        <p-form-item label="机台" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'isMachineTable', validatorRules.isMachineTable]" placeholder="请输入机台"></p-input>
        </p-form-item>
        <p-form-item label="是否巡检" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'isRoundInspect', validatorRules.isRoundInspect]" placeholder="请输入是否巡检"></p-input>
        </p-form-item>
        <p-form-item label="巡检方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['roundInspectMethod', validatorRules.roundInspectMethod]" :trigger-change="true" dictCode="round_inspect_method" placeholder="请选择巡检方式"/>
        </p-form-item>
        <p-form-item label="巡检频率（小时/次）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input-number v-decorator="[ 'roundInspectFrequency', validatorRules.roundInspectFrequency]" placeholder="请输入巡检频率（小时/次）" style="width: 100%"/>
        </p-form-item>
        <p-form-item label="巡检时间段" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择巡检时间段" v-decorator="[ 'roundInspectTimequantum', validatorRules.roundInspectTimequantum]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
        </p-form-item>
        <p-form-item label="巡检抽检方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['rcInspectMethod', validatorRules.rcInspectMethod]" :trigger-change="true" dictCode="rc_inspect_method" placeholder="请选择巡检抽检方式"/>
        </p-form-item>
        <p-form-item label="巡检抽检数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'rcInspectQty', validatorRules.rcInspectQty]" placeholder="请输入巡检抽检数量"></p-input>
        </p-form-item>

      </p-form>
    </p-spin>
    <p-button type="primary" @click="handleOk">确定</p-button>
    <p-button type="primary" @click="handleCancel">取消</p-button>
  </p-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  
  export default {
    name: "MesQcFirstroundInspectRuleModal",
	mixins: [SubmitOnchangMixin],
    components: { 
      JDate,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          processOneNamae: {rules: [
            {required: true, message: '请输入一级工序名称!'},
          ]},
          processOneCode: {rules: [
          ]},
          processTwoName: {rules: [
            {required: true, message: '请输入二级工序名称!'},
          ]},
          processTwoCode: {rules: [
          ]},
          isLineleaderConfirm: {rules: [
            {required: true, message: '请输入是否线长确认!'},
          ]},
          isFirstCheck: {rules: [
            {required: true, message: '请输入是否首检!'},
          ]},
          isDate: {rules: [
            {required: true, message: '请输入日期!'},
          ]},
          isMcode: {rules: [
            {required: true, message: '请输入品号!'},
          ]},
          isLinetype: {rules: [
            {required: true, message: '请输入线别!'},
          ]},
          isMobillno: {rules: [
            {required: true, message: '请输入工单!'},
          ]},
          isMachineTable: {rules: [
            {required: true, message: '请输入机台!'},
          ]},
          isRoundInspect: {rules: [
            {required: true, message: '请输入是否巡检!'},
          ]},
          roundInspectMethod: {rules: [
            {required: true, message: '请输入巡检方式!'},
          ]},
          roundInspectFrequency: {rules: [
            {required: true, message: '请输入巡检频率（小时/次）!'},
          ]},
          roundInspectTimequantum: {rules: [
            {required: true, message: '请输入巡检时间段!'},
          ]},
          rcInspectMethod: {rules: [
            {required: true, message: '请输入巡检抽检方式!'},
          ]},
          rcInspectQty: {rules: [
            {required: true, message: '请输入巡检抽检数量!'},
          ]},
        },
        url: {
          add: '/mes-quality/mesQcFirstroundInspectRule/add',
          edit: '/mes-quality/mesQcFirstroundInspectRule/edit',
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },

      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'processOneNamae','processOneCode','processTwoName','processTwoCode','isLineleaderConfirm','isFirstCheck','isDate','isMcode','isLinetype','isMobillno','isMachineTable','isRoundInspect','roundInspectMethod','roundInspectFrequency','roundInspectTimequantum','rcInspectMethod','rcInspectQty','createBy','createTime','updateBy','updateTime','remark'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
              that.confirmLoading = true;
              let httpurl = '';
              let method = '';
              let formData = Object.assign(this.model, values);
              this.formData = Object.assign(this.model, values);
              //新增触发
              if(!this.model.id){
                httpurl+=this.url.add;
                method = 'post';
                if(this.EnhanceJS.afterAdd){
                  //新增之前
                  let Obj = eval(this.EnhanceJS.afterAdd)
                  new Obj(this)
                }else{
                  console.log("表单提交数据",formData)
                  that.modalFrom(httpurl,formData,method)
                }
              }else{
                //编辑触发
                httpurl+=this.url.edit;
                method = 'put';
                if(this.EnhanceJS.afterEdit){
                 //编辑之前
                  let Obj = eval(this.EnhanceJS.afterEdit)
                  new Obj(this)
                }else{
                  console.log("表单提交数据",formData)
                  that.modalFrom(httpurl,formData,method)
                }
              }
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'processOneNamae','processOneCode','processTwoName','processTwoCode','isLineleaderConfirm','isFirstCheck','isDate','isMcode','isLinetype','isMobillno','isMachineTable','isRoundInspect','roundInspectMethod','roundInspectFrequency','roundInspectTimequantum','rcInspectMethod','rcInspectQty','createBy','createTime','updateBy','updateTime','remark'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>
